<template>
    <Modal class="change-reason-modal" width="540" v-model="changeReasonModal" :mask-closable="false">
        <div slot="header">
            删除/修改提运单
        </div>
        <div class="modal-body">
            <Form ref="formInline" :model="formInline" inline :labelWidth="100" :rules="formInlineRules" @submit.native.prevent>
                <FormItem prop="dataCode" label="更改原因">
                    <Select
                        v-model="formInline.dataCode"
                        clearable
                        filterable
                        :label-in-value="true"
                        :transfer="true"
                        style="width: 300px"
                    >
                        <Option
                            v-for="item in reasonList"
                            :value="item.dataCode"
                            :key="item.dataCode"
                        >{{ item.dataCode + '/' + item.dataName }}</Option>
                    </Select>
                </FormItem>
            </Form>
            <p style="text-align: center">点击“确定”后，修改/删除申请将会自动发送自单一窗口</p>
        </div>
        <div slot="footer">
            <Button type="primary" @click="commitHandle">确定</Button>
            <Button type="primary" @click="closeModal">取消</Button>
        </div>
    </Modal>
</template>

<script>
import commonJs from '../js/common'
export default {
    name: 'ChangeReasonModal',
    data () {
        return {
            changeReasonModal: false,
            formInline: {
                dataCode: '999'
            },
            formInlineRules: {
                dataCode: [
                    { required: true, message: '请选择更改原因', trigger: 'change' }
                ]
            },
            reasonList: commonJs.changeReasonCodeList,
            obj: {}
        }
    },

    methods: {
        init (obj) {
            this.changeReasonModal = true
            this.obj = obj
        },

        commitHandle () {
            this.$refs['formInline'].validate((valid) => {
                if (!valid) {
                    return false
                }
                this.obj.changeReasonCode = this.formInline.dataCode
                this.$emit('sendToSingleWindowHandle', this.obj)
                this.closeModal()
            })
        },

        closeModal () {
            this.$refs['formInline'].resetFields()
            this.changeReasonModal = false
        }
    }
}
</script>
